var backurl2=location.href.toString();
var back_url = encodeURIComponent(backurl2);
function $(_id){
	return document.getElementById(_id);
}

var isfilm0 = false;
var isfilm1 = false;

if(false){
   isfilm1 = true;
}if(true){
   isfilm0 = true;
}if(false){
	isfilm0=false;
	isfilm1 = false;
}

document.onkeypress = grabEvent;
document.onirkeypress = grabEvent;
document.onkeydown = grabEvent;
document.onsystemevent = grabEvent;
function grabEvent(event){
	var key_code = event.which;
		switch(key_code){
		case 1://上
		case 38:
			up();
			return 0;
			break;
			
		case 2://下
		case 40:
			down();
			return 0;
			break;
			
		case 3://左
		case 37:
			left();
			return 0;
			break;
			
		case 4://右
		case 39:
			right();
			return 0;
			break;
		
		case 13://确定
			sel();
			return 0;
			break;

		case 4012: 
		case 4021: 
		case 4404: 
		case 4405:
		case 4408:
		return 0;
		break;
	}
}

var menuHrefs = new Array(5);
var jiageHrefs = new Array(2);
var tuijianHrefs = new Array(2);
var btnHrefs = new Array(3);
var whiteColor= "#FFFFFF",blackColor = "#000000";


/////////////////////////////////////* 剧情 按钮链接*/////////////////////////////////////
menuHrefs[0] = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/common/content.jsp?assetId=4508042&assetType=36&backUrl="+window.location.href+"&indexUrl=http://utc.hzdtv.tv:80/folder/iptvtest/RDIPTV_HZHX_IPS_02133041934619859/iptvtest_001.page&lmUrl=/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";

/////////////////////////////////////* 收藏 按钮链接*/////////////////////////////////////
menuHrefs[1] = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/common/add.jsp?u=&root=http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712&assetId=4508042&assetType=36&folderCode=iptvtest_001_011_003&backUrl="+window.location.href+"&indexUrl=http://utc.hzdtv.tv:80/folder/iptvtest/RDIPTV_HZHX_IPS_02133041934619859/iptvtest_001.page&lmUrl=/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";

/////////////////////////////////////* 最近点播 按钮链接*/////////////////////////////////////
menuHrefs[2] = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/common/latestClick.jsp?u=&folderCode=iptvtest_001_011_003&backUrl="+window.location.href+"&indexUrl=http://utc.hzdtv.tv:80/folder/iptvtest/RDIPTV_HZHX_IPS_02133041934619859/iptvtest_001.page&lmUrl=/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";

/////////////////////////////////////* 评分 按钮链接*/////////////////////////////////////
menuHrefs[3] = "#menu4";

/////////////////////////////////////* 帮助 按钮链接*/////////////////////////////////////
//menuHrefs[4] = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/common/help.jsp?backUrl="+window.location.href+"&indexUrl=http://utc.hzdtv.tv:80/folder/iptvtest/RDIPTV_HZHX_IPS_02133041934619859/iptvtest_001.page&lmUrl=/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";

menuHrefs[4] ="http://125.210.229.188/book?stbid=&filename=超时空救兵&fileid=4508042&backurl="+back_url;
/////////////////////////////////////* 流畅  按钮链接*/////////////////////////////////////
jiageHrefs[0] = "#";

/////////////////////////////////////* 高清  按钮链接*/////////////////////////////////////

jiageHrefs[1] = "#";


tuijianHrefs[0] = [];
tuijianHrefs[1] = [];


//获取当前栏目下前三条资产列表

/////////////////////////////////////* 精彩推荐第一行  3个链接*/////////////////////////////////////
var num = 0;



tuijianHrefs[0][num] = {text:getSubStr("地心历险记",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=1008123"};
	num++;
	



tuijianHrefs[0][num] = {text:getSubStr("甜蜜的惊喜",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4550097"};
	num++;
	



tuijianHrefs[0][num] = {text:getSubStr("孤独的死亡之所",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4508475"};
	num++;
	



tuijianHrefs[0][num] = {text:getSubStr("临床医生",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4508273"};
	num++;
	



var ck=0;

		

	
		
		tuijianHrefs[0][ck] = {text:getSubStr("夜上海",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=1065913"};
		ck++;
			

	
		
		tuijianHrefs[0][ck] = {text:getSubStr("战国",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=1065995"};
		ck++;
			


/////////////////////////////////////* 精彩推荐第二行  3个链接*/////////////////////////////////////
var rowNum = 0;



tuijianHrefs[1][rowNum] = {text:getSubStr("奋斗",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=927896"};
	rowNum++;
		



tuijianHrefs[1][rowNum] = {text:getSubStr("杀手欧阳盆栽",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4371439"};
	rowNum++;
		



tuijianHrefs[1][rowNum] = {text:getSubStr("新福尔摩斯三部曲",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=4419558"};
	rowNum++;
		



tuijianHrefs[1][rowNum] = {text:getSubStr("巴勒斯坦恶狼谷",5), url:"http://utc.hzdtv.tv:80/a?t=36&u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011_003&a=963813"};
	rowNum++;
		



var sk=0;

listLength1 = tuijianHrefs[0].length-1;
listLength2 = tuijianHrefs[1].length-1;
/////////////////////////////////////* 返回  按钮链接*/////////////////////////////////////
btnHrefs[0] = "movie_list.htm";

/////////////////////////////////////* 栏目 按钮链接*/////////////////////////////////////
btnHrefs[1] = "index.htm";

/////////////////////////////////////* 首页   按钮链接*/////////////////////////////////////
btnHrefs[2] = "http://utc.hzdtv.tv:80/a?u=RDIPTV_HZHX_IPS_02133041934619859&f=iptvtest_001_011";

/**
 * 0: menu; 1:fen, 2:jiage, 3:tuijian, 4:btn
 */
var area = 0;

//menu
var _menu_index = 0;
var max_menu_index = 4;

//fen
var _fen_index = 0;
var max_fen_index = 1;

//jiage

var _jiage_index = 0;
var max_jiage_index = 1;

//list
var listFlag = 0;
var listIndex = 0;
var listLength1 = 2;
var listLength2 = 2;
/*
var _list_top = 536;
var inc_list_top = 44;
var init_list_left = 477;
var max_list_left = 804;
var _list_left = init_list_left;
var inc_list_left = 173;*/

//btn
var _btn_index = 0;
var max_btn_index = 2;

//pinfen
var pingfen_index = 0;

//sync
var is_sync = false;

function up(){
	if(is_sync) return;
	
	switch(area){
		case 0:
			break;
		case 2:
			area = 0;
			jiageOut();
			menuIn();
            break;
		case 3:
			if(listFlag == 0){
				area = 2;
				listOut();
				jiageIn();
			}else{
				listFocusChange(listFlag-1,listIndex);
			}
			break;
		case 4:
			area = 3;
			btnOut();
			listIn();
			break;
		case 5:
			pingfen_up();
			break;
}
	
}
function down(){
	if(is_sync) return;
	
	switch(area){
		case 0:
			menuOut();
			area = 2;
			jiageIn();
			break;
		case 2:
			area = 3;
			jiageOut();
			listIn();
			break;
		case 3:
			if(listFlag == 1){
				area = 4;
				listOut();
				btnIn();
			}else{
				listFocusChange(listFlag+1,listIndex);
			}
			break;
		case 4:
			break;
		case 5:
			pingfen_down();
			break;
}
	
}

function left(){
	switch(area){
		case 0:
			incMenu(-1);
			break;
		case 2:
			if(!incJiage(-1)) up();
			break;
		case 3:
			if(listIndex > 0){
				listFocusChange(listFlag,listIndex-1);
			} else if(listFlag == 1){
				listFocusChange(listFlag-1,listLength1);
			} else {
				up();
			}
			break;
		case 4:
			if(!incBtn(-1)) up();
			break;
	}
} 
function right(){
	switch(area){
		case 0:
			if(!incMenu(1)) down();
			break;
		case 2:
			if(!incJiage(1)) down();
			break;
		case 3:
			if(listFlag == 0){
				if(listIndex < listLength1){
					listFocusChange(listFlag,listIndex+1);
				}else{
					listFocusChange(listFlag+1,0);
				}
			}else{
				if(listIndex < listLength2){
					listFocusChange(listFlag,listIndex+1);
				}else{
					down();
				}
			}
			break;
		case 4:
			incBtn(1);
			break;
	}
} 

//menu functions
function menuIn(){
	$("menu_"+_menu_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/mh"+_menu_index+".png";
}
function menuOut(){
	$("menu_"+_menu_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/m"+_menu_index+".png";
}

function incMenu(inc){
	var new_menu_index = _menu_index + inc;
	if(new_menu_index<0 || new_menu_index>max_menu_index) return false;

	menuOut();
	_menu_index = new_menu_index;
	menuIn();
	return true; 
}

//btn functions
function btnIn(){
	$("btn_"+_btn_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/btn_h"+_btn_index+".png";
}
function btnOut(){
	$("btn_"+_btn_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/btn"+_btn_index+".png";
}

function incBtn(inc){
	var new_btn_index = _btn_index + inc;
	if(new_btn_index<0 || new_btn_index>max_btn_index) return false;

	btnOut();
	_btn_index = new_btn_index;
	btnIn();
	return true;
}



//jiage functions
function jiageIn(){

	if((isfilm0 == true)&&(isfilm1 == true)){
		$("jiage"+_jiage_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/play_h"+_jiage_index+".png";
        $("jiagenum"+_jiage_index).style.color = whiteColor;
		$("jiagetext"+_jiage_index).style.color = whiteColor; 
		}
	else if((isfilm0 == true)&&(isfilm1 == false)){
		_jiage_index = 0;
		$("jiage"+_jiage_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/play_h"+_jiage_index+".png";
        $("jiagenum"+_jiage_index).style.color = whiteColor;
        $("jiagetext"+_jiage_index).style.color = whiteColor; 
		$("jiage1").style.visibility = "hidden";
		$("jiagenum1").style.visibility = "hidden";
        $("jiagetext1").style.visibility = "hidden";
        $("Layer3").style.visibility = "hidden";
}
	else if((isfilm0 == false)&&(isfilm1 == true)){
		_jiage_index = 1;
		$("jiage"+_jiage_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/play_h"+_jiage_index+".png";
        $("jiagenum"+_jiage_index).style.color = whiteColor;
		$("jiagetext"+_jiage_index).style.color = whiteColor; 
		}

}
function jiageOut(){
	$("jiage"+_jiage_index).src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/play"+_jiage_index+".png";
	$("jiagenum"+_jiage_index).style.color = blackColor;
	$("jiagetext"+_jiage_index).style.color = blackColor;
}
function incJiage(inc){
	var new_jiage_index = _jiage_index + inc;
	if(new_jiage_index<0 || new_jiage_index>max_jiage_index) return false;
	
	if((isfilm0 == true)&&(isfilm1 == true)){
		jiageOut();
		_jiage_index  += inc;
		jiageIn();
		return true;
		}
	else if((isfilm0 == false)&&(isfilm1 == true)){
		if(inc == -1){
			return false;
			}
		else{
			jiageOut();
			_jiage_index  += inc;
			jiageIn();
			return true;
			}
		}
	else if((isfilm0 == true)&&(isfilm1 == false)){
		if(inc == 1){
			return false;
			}
		else{
			jiageOut();
			_jiage_index  += inc;
			jiageIn();
			return true;
			}
		}
	
	
}

//////////////////list
//list functions
function listIn(){
	$("list"+listFlag+listIndex).style.color = "#ffffff";
	$("list"+listFlag+listIndex).style.backgroundImage = "url(http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/float_choose.png)";	
}

function listOut(){
	$("list"+listFlag+listIndex).style.color = "#000000";
	$("list"+listFlag+listIndex).style.backgroundImage = "url(http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/new/touming.png)";
}

function listFocusChange(_listFlag,_listIndex){
	listOut();
	listFlag = _listFlag;
	listIndex = _listIndex;
	listIn();
}
/*
function listIn(){
	//$("float_choose").style.opacity = 1;
	$("float_choose").style.visibility = "visible";
	listWhite();
}
function listOut(){
	//$("float_choose").style.opacity = 0;
	$("float_choose").style.visibility = "hidden";
	clearTimer();
	listBlack();
}
var listTimeout;
function clearTimer(){
	if(listTimeout != null){
		clearTimeout(listTimeout);
		listTimeout = null;
	}
}
function listWhite(){
	clearTimer();
	var __text = $("list"+_list+_list_index);
	listTimeout = setTimeout(function(){__text.style.color = "#ffffff"}, 200);
}
function listBlack(){
	$("list"+_list+_list_index).style.color = "#000000";
}
function setTFList(__list, __list_index){
	$("float_choose").style.left = _list_left + "px";
	$("float_choose").style.top = _list_top + "px";

	listBlack();
	_list = __list;
	_list_index = __list_index;
	listWhite();
} 

function incTopList(inc){
	$("float_choose").style.top = _list_top + "px";
	listBlack();
	_list += inc;
	listWhite();
}
function incLeftList(inc){
	$("float_choose").style.left = _list_left + "px";
	listBlack();
	_list_index  += inc;
	listWhite();
}*/

function sel(){
	//alert("area="+area);
	switch(area){
		case 0:
			if(_menu_index == 3){
				pingfen();
				break;
				}
			else{
              window.location.href = menuHrefs[_menu_index];
			break;}
		case 2:
		    //alert("_jiage_index="+_jiage_index);
			if(_jiage_index==0){
				doAuth1();
			}else{
				doAuth2();
		}
			break;
		case 3:
			window.location.href = tuijianHrefs[listFlag][listIndex].url;
			break;
		case 4:
			window.location.href = btnHrefs[_btn_index];
			break;
		case 5:
			pingfen_sel();
			break;
}
}
function pingfen(){
	area = 5;
	$("Layer1").style.visibility = "visible";
	$("Layer2").style.visibility = "hidden";
	document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=zhutu&asset_id=4508042";
	}
function pingfen_down(){
	if((pingfen_index >= 0)&(pingfen_index <= 3)){
		//$("l"+pingfen_index).style.color = blackColor;
        pingfen_index += 1;
		$("pingfen_float").style.top = 52 + pingfen_index*60 + "px";
		$("l"+pingfen_index).style.color = whiteColor;
}
	else if(pingfen_index == 4){
		//$("l"+pingfen_index).style.color = blackColor;
        pingfen_index += 1;
		$("pingfen_float").style.visibility = "hidden";
		$("pingfen_back").src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/pingfen_back_chg.png";
		}
	}
function pingfen_up(){
	if((pingfen_index >= 1)&(pingfen_index <= 4)){
		//$("l"+pingfen_index).style.color = blackColor;
        pingfen_index -= 1;
		$("pingfen_float").style.top = 52 + pingfen_index*60 + "px";
		$("l"+pingfen_index).style.color = whiteColor;
}
	else if(pingfen_index == 5){
		pingfen_index -= 1;
		$("l"+pingfen_index).style.color = whiteColor;
        $("pingfen_float").style.visibility = "visible";
        $("pingfen_back").src = "http://utc.hzdtv.tv:80/templates/iptvtest/runtime/iptv0712/images/mov/pingfen_back.png";
}
	}
function pingfen_sel(){
	//alert("1");
	switch(pingfen_index){
		case 0:
			document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=votezhutu&asset_id=4508042&id=-3";
			//dopingfen();
			dopingjia()
			break;
		case 1:
			document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=votezhutu&asset_id=4508042&id=-4";
		//dopingfen();
		dopingjia()
			break;
		case 2:
			document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=votezhutu&asset_id=4508042&id=-5";
		//dopingfen();
		dopingjia()
			break;
		case 3:
			document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=votezhutu&asset_id=4508042&id=-6";
		//dopingfen();
		dopingjia()
			break;
		case 4:
			document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=votezhutu&asset_id=4508042&id=-7";
		//dopingfen();
		dopingjia()
			break;
			
		case 5:
			area = 0;
			$("Layer1").style.visibility = "hidden";
			$("Layer2").style.visibility = "visible";
			break;
	}
	}

function dopingfen(){
	//document.getElementById("f1").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=zhutu&asset_id=4508042";

}
function dopingjia(){
	document.getElementById("f2").src = "http://125.210.228.71/flowerHLW/newAction.do?opAction=pingjia&asset_id=4508042";

}
function doAuth1(){
	
	//if(""=="1"||""=="9"){
			//询价成功		
			var tvid="1117004090C3585937162D3D";
			//TODO 修改为订购页面地址
			//var toUrl= "http://utc.hzdtv.tv/templates/iptvtest/runtime/iptv0712/template/auth.jsp?"; 
            var toUrl= "auth.htm?"; 			
			toUrl+="iptvid="+tvid;
			//toUrl+="&userToken=";
			toUrl+="&userToken=";
			toUrl+="&contentId=4508042";
		//alert(toUrl);
			toUrl+="&serviceId=139259706";
			toUrl+="&returnUrl=";
			toUrl+="&contentName=超时空救兵";
			
			//toUrl+="&cpId=CP2301";
			toUrl+="&cpId=814161";
			toUrl+="&ppvPath=票房风云";
			
			toUrl+="&toUrl=&isIpqam=0&assetid=";
			toUrl+="&currentFolderCode=iptvtest_001_011_003&isHd=0";
			toUrl+="&stbId=&userId=&fee=&ppvId=139259706&folderId=36072&userAgent=Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2&assetType=36";
			//alert(toUrl);
			window.location.href=toUrl;			
	//}else{
	//	iPanel.mainFrame.location.href="http://utc.hzdtv.tv/templates/iptvtest/runtime/iptv0712/common/error_family.jsp";
	//}
}

function doAuth2(){
	//alert("2");
	if(""=="1"||""=="9"){
			//询价成功
			var tvid="";
			//TODO 修改为订购页面地址
			var toUrl= "http://utc.hzdtv.tv/templates/iptvtest/runtime/iptv0712/template/auth.jsp?";  
			toUrl+="iptvid="+tvid;
			toUrl+="&userToken=";
			toUrl+="&contentId=4508042";
		
			toUrl+="&serviceId=";
			toUrl+="&returnUrl=";
			toUrl+="&contentName=超时空救兵";
			
			//toUrl+="&cpId=CP2301";
			toUrl+="&cpId=814161";
			toUrl+="&ppvPath=票房风云";
			
			toUrl+="&toUrl=&isIpqam=0&assetid=";
			toUrl+="&currentFolderCode=iptvtest_001_011_003&isHd=1";
			toUrl+="&stbId=&userId=&fee=&ppvId=&folderId=36072&userAgent=Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2&assetType=36";
			//alert(toUrl);
			iPanel.overlayFrame.location.href=toUrl;	
			//window.location.href=toUrl;	
	}else{
		iPanel.mainFrame.location.href="http://utc.hzdtv.tv/templates/iptvtest/runtime/iptv0712/common/error_family.jsp";
	}
}

function init(){
	//alert(tuijianHrefs[0].length);
	for(var i=0; i<tuijianHrefs[0].length&&i<3; i++){
		

		$("list0"+i).innerText = tuijianHrefs[0][i].text;
	}

	for(var j=0; j<tuijianHrefs[1].length&&j<3; j++){

		$("list1"+j).innerText = tuijianHrefs[1][j].text;
	}
}

//截取字符串
function getSubStr(str,num){
    var num = num;
	if(str.length > num){
		str = str.substr(0,num)+"...";
	}
	return str;
}